/**
 * 
 */
package com.cqcis.uip.module.salary.oper.dao;

import java.util.List;

import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.cqcis.uip.base.framework.utils.JdbcUtil;
import com.cqcis.uip.base.framework.utils.StringUtil;
import com.cqcis.uip.module.salary.oper.SalaryConstants;
import com.cqcis.uip.module.salary.oper.domain.Salarylevel;

/**
 * @author 李世军
 *
 * 创建于 2012-3-7 下午01:06:30
 */
public class SalarylevelDao extends JdbcDaoSupport {
	private static String FIELDS = " id, base_salary, performance_salary, secrecy_salary, traffic_subsidy, comm_subsidy, salary_grade, position_level, remark " ;
	private static String SELECT_SQL = " select "+FIELDS+" from resourcecontrol_salarylevel ";
	private static String GET_SQL = " select "+FIELDS+" from resourcecontrol_salarylevel where salary_grade=? and position_level=? ";
	
	
	/**
	 * 查询
	 * @return
	 */
    public List<Salarylevel> query() {
    	return JdbcUtil.queryForList(this, Salarylevel.class, SELECT_SQL);
    }
    
    /**
     * 获取指定工资
     * @param salaryGrade	新档
     * @param positionLevel 等级
     * @return
     */
    public Salarylevel get(String salaryGrade, String positionLevel) {
    	return JdbcUtil.queryForObject(this, Salarylevel.class, GET_SQL, salaryGrade, positionLevel);
    }
    
    private static String MONTH_FEE_SQL = " select month_fee+attendance_deduction+other_deduction+out_deduction+market_deduction as monthfee "
    									+" from employecontrol_attendance where employe_id=? and month>=? and month<=? " ;
    /**
     * 获取全勤工资
     * @param employeId
     * @return
     */
    public float getMonthFee(String employeId){
    	Float f = JdbcUtil.queryForObject(this, Float.class, MONTH_FEE_SQL, employeId, SalaryConstants.getStartDate(), SalaryConstants.getEndDate()) ;
    	if(f!=null){
    		return f ;
    	}
    	
    	return 0F ;
    }
    
    private static String FORMANCE_SQL = " select finally_no from employecontrol_employeperformance where state=1 and employe_id=? and month>=? and month<=? " ;
    /**
     * 获取绩效分数
     * @param employeId
     * @return
     */
    public float getFormanceNo(String employeId){
    	Float f = JdbcUtil.queryForObject(this, Float.class, FORMANCE_SQL, employeId, SalaryConstants.getStartDate(), SalaryConstants.getEndDate()) ;
    	if(f==null)
    		return 1F ;
    	
    	if(f>=85F)
    		return 1F ;
    	else
    		return f/100F ;
    }
    
    private static String INSURE_SQL = " select a+b+c+d+e+f as insure from employecontrol_employeinsure where  employe_id=? and month>=? and month<=? " ;
    
    /**
     * 获取保险和个税扣款
     * @param employeId
     * @return
     */
    public float getInsure(String employeId){
    	Float f = JdbcUtil.queryForObject(this, Float.class, INSURE_SQL, employeId, SalaryConstants.getStartDate(), SalaryConstants.getEndDate()) ;
    	if(f!=null){
    		return f ;
    	}
    	
    	return 0F ;
    }
}
